<!-- 会签管理 > 待发送会签单位列表 -->
<template>
	<view>
		<!-- <van-contact-card type="add" @click="onAdd" add-text="添加更多会签单位"/> -->
		<van-cell title="添加更多会签单位" icon="plus" @click="onAdd" is-link />
      <template v-if="unConSignList.length>0">
        <van-cell is-link title="限时办理天数选择:" :value="limitDaysName" @click="showLimitDays = true"/>
        <van-action-sheet v-model="showLimitDays" :actions="limitDaysList" cancel-text="取消" @select="onSelect"
                          get-container="body"/>
      </template>
		<van-list v-model="loading" :finished="finished">
			<van-checkbox-group v-model="result" @change="onChange">
				<van-cell-group>
					<van-cell v-for="(item, index) in unConSignList" clickable :key="index" :title="item.countersignDept"
						@click="toggle(index)">
						<template #label>
							<view class="padding-xs">
								<text class="text-gray text-sm margin-right-sm">接收人:{{item.receiverName}}</text>
							</view>
						</template>
						<template #right-icon>
							<van-checkbox :name="item" ref="checkboxes" />
						</template>
					</van-cell>
				</van-cell-group>
			</van-checkbox-group>
		</van-list>
		<view class="padding-top-lg padding-bottom-lg" v-if="unConSignList.length>0">
			<van-row type="flex" justify="space-around">
				<van-col span="10">
					<van-button :disabled="isDisabled" type="info" round plain hairline block @click="toDelete">删除</van-button>
				</van-col>
				<van-col span="10">
					<van-button :disabled="isDisabled" type="info" round block @click="toSend">发送会签</van-button>
				</van-col>
			</van-row>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			paramObject:{
				proInstId:String,
				fwId:String,
				param01:Object,//获取签批功能菜单所需要的参数
				param02:Object
			},

			unConSignList:Array
		},

		data() {
			return {
              result: [],
              loading: false,
              finished: true, //不显示加载中
              isDisabled: true,
              limitDaysName: '不限时',//限时办理天数选择
              limitDaysCode: '-1',//限时办理天数字典值code
              showLimitDays: false,//是否显示限时办理天数
              dictlimitDays: [],//显示办理天数字典值
              limitDaysList: [],//处理后的显示办理天数字典值，只包含name 和 code
              sendHuiqianObj:{
                receiverIdArr:[],
                limitDaysCode:'-1'
              }
			}
		},
		mounted() {
          this.getDict()
		},
		methods: {
          //限时办理天数
          onSelect(item) {
            this.limitDaysName = item.name
            this.limitDaysCode = item.dictItemCode
            this.showLimitDays = false;
          },
          //获取需要的字典项
          getDict() {
            this.dictlimitDays = this.cache.get('limitDays')//密级
            //给van-action-sheet 赋值
            this.limitDaysList = []
            this.dictlimitDays.forEach((item) => {
              this.limitDaysList.push({name: item.dictItemName, dictItemCode: item.dictItemCode})
            })
          },
			toggle(index) {
				this.$refs.checkboxes[index].toggle();
			},

			onChange(item){
				if(this.result.length > 0){
					this.isDisabled = false
				}else{
					this.isDisabled = true
				}
			},

			onAdd(){
				if(this.paramObject.fwId != undefined){
					uni.navigateTo({
						url:"/pages/caac/submit/add-org?fwId="+this.paramObject.fwId+"&proInstId="+this.paramObject.proInstId
					})
				}else{
					this.$toast('缺少参数：fwid')
				}
			},

			toDelete(){
				this.$dialog.confirm({
				  title: '系统提示',
				  message: '是否确认删除所选单位?',
				}).then(() => {
					let uuidArr = []
					this.result.forEach((item)=>{
						uuidArr.push(item.uuid)
					})
					this.$emit('deleteConSign',{uuids:uuidArr})
					this.isDisabled = true //重置按钮为不可点击
					this.result=[]
				  }).catch(() => {
				    // on cancel
				  });
			},
			toSend(){
				this.$dialog.confirm({
				  confirmButtonColor: '#1989fa',
				  title: '系统提示',
				  message: '是否确认发送会签?',
				}).then(() => {//确定按钮
                  //将选中单位传递给父组件进行会签提交
                  this.result.forEach((item) => {
                    this.sendHuiqianObj.receiverIdArr.push(item.receiverId)
                  })
                  this.sendHuiqianObj.limitDaysCode = this.limitDaysCode
                  this.$emit('sendHuiqian', this.sendHuiqianObj)//result选中的单位
                  this.sendHuiqianObj.receiverIdArr=[]
                  this.sendHuiqianObj.limitDaysCode='-1'
				  }).catch(() => {
				    // on cancel
				  });
			},



		},
	}
</script>

<style scoped>
</style>
